﻿using PracticeCentre.Common;
using PracticeCentre.DataControl;
using PracticeCentre.Modeles;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PracticeCentre.Business
{
    /// <summary>
    /// 系统用户业务控制类
    /// </summary>
    public class SystemUsers
    {
        /// <summary>
        /// 根据用户名、密码或是工号获取系统用户信息
        /// </summary>
        /// <param name="user">要获取的用户</param>
        /// <returns></returns>
        public SystemUser GetLoingUser(SystemUser model)
        {
            try
            {
                DataControlHelper dataHelper = new DataControlHelper();
                SqlParameter[] parameters = new SqlParameter[] {
                    new SqlParameter("@username",model.UserName),
                    new SqlParameter("@userpass",model.UserPass)
                };
                DataTable dt = dataHelper.ExecuteDataTable(ProceduresConfig.GetLoginUserModel, parameters);
                DataModelHandler<SystemUser> datamodel = new DataModelHandler<SystemUser>();
                if (dt.Rows.Count > 0)
                    model = datamodel.FillModel(dt.Rows[0]);
                else
                    model = null;
                return model;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
    }
}
